import urllib.request
import urllib.parse
import json

url = 'https://fanyi.baidu.com/v2transapi?from=en&to=zh'
data = {
    'from': 'en',
    'to': ' zh',
    'query': '1ovetrans',
    'type': 'realtime',
    'simple_means_flag': '3',
    'sign': ' 198772.518981',
    'token': '5483bfa652979b41f9c90d91f3de875d',
    'domain': 'common'
}

headers = {
    # 'accept': 'text/event-stream',
    # 'accept-encoding': 'gzip, deflate, br, zstd',
    # 'accept-language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7',
    # 'acs-token': '1728468007966_1728529573699_FzR/9hHU9WYzEjzg8+tAJ6+6Sb4hYJ70fyXFJJa3R1f1chsADPtmr3+9gYxKYM1ukyV/qvUMCKI6924klfnuVqpEfVL2SzSo43J4Dqn42G78qOM1OaF6G2AdwV9DFLvkvS/Ba1AnmADbZFJ5vinmIRdR99tKgdv5v3hKk9ZMeGroqdNvjL0ymcuTiuKsv/2ZgUh27bgrGLuEsq2p1xaOtRYQ2Fb8VZ+75MODSLxssMgTZgu8jhzEnPMuAmH53oKd9mCX86o8nmJLRgzInv7L2grnqW22Vz6ElYbVY6aVMNxlWKDHYdFw+FRW425Lv4dFHkdSgiFW4XfIahW6bHRN8oOZNk1hF4CyKMCxWRsWOgpys2fm/emD86RrXPHTts+CsI3qrtBaqxMGXXgjDiIbC9qIB4e22USc5BDGOQWRhZlP62zrm9lARgcKvXqluViD',
    # 'connection': 'keep-alive',
    # 'content-length': '142',
    # 'content-type': 'application/json',
    'Cookie': 'BAIDUID_BFESS=8D7E0B467197C74B1B73EFBE01CB55A7:FG=1; BIDUPSID=8D7E0B467197C74B1B73EFBE01CB55A7; PSTM=1718617493; ZFY=Hk907Gp9D7h0yf4kB2GrKftFf1oyqjKWImUGXI5zOP0:C; H_PS_PSSID=60598_60360_60796_60826; H_WISE_SIDS=110085_603327_307086_613055_613408_618457_618440_619529_619881_620010_620343_613974_621187_621397_610630_620179_621040_622290_622279_614596_620092_622514_622493_622494_1991607_1991637_311849_1991999_1991941_620374_1992013_622118_1991948_615157_1992049_1992043_617084_622908_623077_620472_1991788_623157_622439_623271_623335_623387_623369_623460_623488_623489_623517_620474_623606_623612_623536_623659_612886_623098_623652_612517_623760_621954_623851_1991918_623889_623883_607111_623755_622732_621714_623956_623996_623909_624008_624004_624018_624012_624022_610108_622641_622378_623391; delPer=0; PSINO=1; H_WISE_SIDS_BFESS=110085_603327_307086_613055_613408_618457_618440_619529_619881_620010_620343_613974_621187_621397_610630_620179_621040_622290_622279_614596_620092_622514_622493_622494_1991607_1991637_311849_1991999_1991941_620374_1992013_622118_1991948_615157_1992049_1992043_617084_622908_623077_620472_1991788_623157_622439_623271_623335_623387_623369_623460_623488_623489_623517_620474_623606_623612_623536_623659_612886_623098_623652_612517_623760_621954_623851_1991918_623889_623883_607111_623755_622732_621714_623956_623996_623909_624008_624004_624018_624012_624022_610108_622641_622378_623391; BDORZ=AE84CDB3A529C0F8A2B9DCDD1D18B695; BA_HECTOR=848l24aga02ka4a52g8ha581156a1o1jgeg9b1v; PSCBD=31%3A1; SE_LAUNCH=5%3A1728528682_31%3A28808811; ab_sr=1.0.1_OTQzNTFhMTI1OTNhZjMzNzNjMmE3Njk0ZDM0MGQ5MTAzOTk4Njk2NGIyODk1Y2UyNTNjZWVhMDhmNGU3OWY4MDE3ZGQzYzhmY2Q3NDNkZDBkYTRlYTYxMGVlZmY2ZWM1Y2IwMzE5YTg4OGVmZmI4NDQ4MTlmZjQ2YWRhOTkyOTAyYjc1NmZhNDliMjA3ZTcwYzc2ZTk4Nzk4MmMxNmYzNA==; ppfuid=FOCoIC3q5fKa8fgJnwzbE67EJ49BGJeplOzf+4l4EOvDuu2RXBRv6R3A1AZMa49I27C0gDDLrJyxcIIeAeEhD8JYsoLTpBiaCXhLqvzbzmvy3SeAW17tKgNq/Xx+RgOdb8TWCFe62MVrDTY6lMf2GrfqL8c87KLF2qFER3obJGkdximGddNRzN/k8jMV5fwkGEimjy3MrXEpSuItnI4KD9YYnlpuDKnYcZ2UjenP+8h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b562427&ss=m22pcp6j&sl=4&tt=23y&bcn=https%3A%2F%2Ffclog.baidu.com%2Flog%2Fweirwood%3Ftype%3Dperf&ld=nty&nu=9y8m6cy&cl=dem"'
    # 'host': 'fanyi.baidu.com',
    # 'origin:https': '//fanyi.baidu.com',
    # 'referer:https': '//fanyi.baidu.com/mtpe-individual/multimodal?query=%E4%B8%AD%E5%9B%BD%E4%BA%BA&lang=zh2en',
    # 'sec-ch-ua': '"Google Chrome";v="129", "Not=A?Brand";v="8", "Chromium";v="129"',
    # 'sec-ch-ua-mobile': '?0',
    # 'sec-ch-ua-platform': '"Windows"',
    # 'sec-fetch-dest': 'empty',
    # 'sec-fetch-mode': 'cors',
    # 'sec-fetch-site': 'same-origin',
    # 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36'
}

# post的参数必须要进行编码  并且必须是字节型的数据 使用.encode('utf-8')
data = urllib.parse.urlencode(data).encode('utf-8')

request = urllib.request.Request(url=url, data=data, headers=headers)
response = urllib.request.urlopen(request)
html = response.read().decode('utf-8')
print(json.loads(html))
